package config

import (
	"os"
	"path/filepath"

	"github.com/jinzhu/configor"
)

var Config = struct {
	HTTPS     bool   `default:"false" env:"HTTPS"`
	Certpath  string `default:"" env:"Certpath"`
	Certkey   string `default:"" env:"Certkey"`
	Port      uint   `default:"80" env:"PORT"`
	Host      string `default:"" env:"Host"`
	JwtExp    int    `default:"" env:"JwtExp"`
	JwtSecret string `default:"" env:"JwtSecret"`
	JwtString string `default:"" env:"JwtString"`
	Admin     struct {
		UserName        string `env:"AdminUserName" default:"username"`
		Name            string `env:"AdminName" default:"name"`
		Pwd             string `env:"AdminPwd" default:"123456"`
		RoleName        string `env:"AdminRoleName" default:"superadmin_role"`
		RoleDisplayName string `env:"TenantRoleDisplayName" default:"商户管理员"`
	}
	DB struct {
		Name     string `env:"DBName" default:"goirisadminapi"`
		Adapter  string `env:"DBAdapter" default:"mysql"`
		Host     string `env:"DBHost" default:"mysql"`
		Port     string `env:"DBPort" default:"3306"`
		User     string `env:"DBUser" default:"root"`
		Password string `env:"DBPassword" default:"123456"`
	}
	REDIS struct {
		Network     string `env:"RedisNetwork" default:"tcp"`
		Addr        string `env:"RedisAddr" default:"127.0.0.1:6379"`
		Password    string `env:"RedisPassword" default:""`
		Database    int    `env:"ReidsDatabase" default:"12"`
		MaxIdle     int    `env:"RedisMaxIdle" default:"0"`
		MaxActive   int    `env:"RedisMaxActive" default:"20"`
		IdleTimeout int    `env:"RedisTimeout" default:"0"`
		Timeout     int    `env:"RedisTimeout" default:"0"`
		Prefix      string `env:"RedisPrefix" default:""`
		Keyttl      int    `env:"RedisKeyttl" default:""`
	}
}{}

var Root = os.Getenv("GOPATH") + "/src/IrisJwtCasbin/"

func init() {
	//注意yml配置文件中的变量名必须是小写开头
	if err := configor.Load(&Config, filepath.Join(Root, "config/application.yml")); err != nil {
		panic(err)
	}
}
